<?php
IF($report == '1') { $reportname = "All_Part_Requests"; }
IF($report == '2') { $reportname = "All_Open_Part_Requests"; }
IF($report == '3') { $reportname = "All_Closed_Part_Requests"; }
IF($report == '4') { $reportname = "All_Cancelled_Part_Requests"; }

IF($report != '8') {
    $line = array('HEADER_NUMBER', 'DETAIL_NUMBER', 'X_TO', 'X_FROM', 'X_TODATE', 'WEBORDERID', 'TRACKINGNUMBER', 'RUNID');
  	$csv->addRow($line);
  	
  	WHILE($row = mysql_fetch_array($result))
  	  {
    	$line = array($row["headernumber"],$row["detailnumber"],$row["xto"],$row["xfrom"],$row["xtodate"],$row["weborderid"],$row["trackingnumber"],$runid);
    	$csv->addRow($line);
  	}
}
ELSE {
	$line = array('HEADER_NUMBER', 'DETAIL_NUMBER', 'X_TO', 'X_FROM', 'X_TODATE', 'WEBORDERID', 'TRACKINGNUMBER', 'EVENTDATE', 'EVENTNUMBER', 'EVENTTEXT', 'RUNID');
  	$csv->addRow($line);
  	
  	WHILE($row = mysql_fetch_array($result))
  	  {
		$line = array($row["headernumber"],$row["detailnumber"],$row["xto"],$row["xfrom"],$row["xtodate"],$row["weborderid"],$row["trackingnumber"],$row["eventdate"],$row["eventnumber"],$row["eventtext"],$runid);
    	$csv->addRow($line);
  	}
}

echo $csv->render('EXPORT_'.$reportname.'_RUNID-'.$runid.'.csv');

?>